import socket

#!/usr/bin/python
# -*- coding: utf-8 -*-

import time
import socket
import rospy
from std_msgs.msg import String


tcpserver = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcpserver.bind(("", 9020))
tcpserver.listen(5)


rospy.init_node('tcptalker',anonymous=0)
pub=rospy.Publisher('tcptopic',String,queue_size=10)

while not rospy.is_shutdown():
    conn, addr = tcpserver.accept()
    print(conn)
    while True:
        if 1<2:
            data = conn.recv(1024)
            print(data.decode("utf-8"))

            pub.publish(data)
            ret_data = "OK, starting..."
            conn.send(ret_data.encode('utf-8'))

        #except Exception:
        #    break
        #    print("1212")
    conn.close()
